//工具类
var util={
	el:{
		tap:function(el,fun){
			var target=document.getElementById(el);
			if(!target){
				return;
			}
			target.addEventListener("tap",fun);
		}
	}
}

//初始化ui
mui.init();

var gallery = mui('.mui-slider');
gallery.slider({
  interval:5000//自动轮播周期，若为0则不自动播放，默认为0；
});
mui('.mui-scroll-wrapper').scroll({
	deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
});

mui("#js-nav-bottom").on('tap','.mui-tab-item',function(){
  var href = this.getAttribute("href");
  mui.openWindow({
    url:href+"?1"
  });
}) 
/*我的订单页点击*/
mui("#segmentedControl").on('tap','.mui-control-item',function(){
  var href = this.getAttribute("href");
  mui.openWindow({
    url:href+"?2"
  });
}) 

//顶部地址设置按钮
util.el.tap("js-btn-address-set",function(){
	if(location.href.indexOf("/item")>0){
		location.href="../addressset.html";
	}else{
		location.href="addressset.html";
	}
});

//顶部地址设置展开收缩按钮
mui("#js-header-bar").on("tap",".js-addrset-swtich",function(){
	//如果未设置地址不能隐藏设置栏
	if(!localStorage.address_block){
		return;
	}
	
	//收缩或展开地址栏
	$("#js-header-bar").toggleClass("hidden-addrset");
	//收缩时移除地址栏占位空间，展开时需要占用滚动空间
	$("#js-fold-space").toggleClass("scroll-fix")
})

//显示设置的地址
getAddress(function(addr){
	$("#spanClientAddress").text(addr.district||addr.city);
});
